//
//  MineCarCell.m
//  carcareIOS
//
//  Created by 王然 on 16/8/5.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "MineCarCell.h"
#import "NSString+CGSize.h"

#define CELL_HEIGHT (75)

#define Label_Color (COLOR_HEXSTRING(@"#2e2e2e"))
#define Label_Gray_Color (COLOR_HEXSTRING(@"#9c9c9c"))

@interface MineCarCell()

@property (nonatomic , strong) UIImageView * iconImageV;

@property (nonatomic , strong) UILabel * titleL;

@property (nonatomic , strong) UILabel * grayTitleL;//车牌右侧带边框的label

@property (nonatomic , strong) UILabel * detailL;

@end
@implementation MineCarCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createUI];
    }
    return self;
}
- (void)createUI
{
    CGFloat iconX = 9 * __MAIN_RATIO_375;
    UIImage * icon = ImageNamed(@"BRCarStyleNormalImage");
    CGFloat iconImageVW = 107 * __MAIN_RATIO_375 ;
    CGFloat iconImageVH = iconImageVW * icon.size.height / icon.size.width;
    self.iconImageV = [[UIImageView imageViewWithFrame:CGRectMake(iconX, (CELL_HEIGHT - iconImageVH) / 2, iconImageVW, iconImageVH) image:icon] setupOnView:self];
    
    
    UIImage * rightImage = ImageNamed(@"cell_right");
    CGFloat rightIVX = __MAIN_WIDTH - 15 * __MAIN_RATIO_375 - rightImage.size.width / 2 ;
   self.rightImageV = [[UIImageView imageViewWithCenter:CGPointMake(rightIVX , CELL_HEIGHT / 2) image:rightImage] setupOnView:self];
    
    CGFloat titleLX = self.iconImageV.right + 7 * __MAIN_RATIO_375;
    CGFloat titleLW = 110;
    CGFloat titleLY = 13;
    CGFloat titleLH = 21;
    self.titleL = [[UILabel labelWithFrame:CGRectMake(titleLX, titleLY, titleLW, titleLH) font:FONT_DEFAULT_Bold(16) text:@"" textColor:Label_Color] setupOnView:self];
    self.titleL.backgroundColor = [UIColor clearColor];
    
    CGFloat grayTitleLH = 18;
    CGFloat grayTitleLW = 52;
    self.grayTitleL = [[[[[UILabel labelWithFrame:CGRectMake(self.titleL.right, (titleLH - grayTitleLH) / 2 + self.titleL.top, grayTitleLW, grayTitleLH) font:FONT_DEFAULT_Light(11) text:@"绑定车辆" textColor:COLOR_HEXSTRING(@"#9c9c9c")] setupOnView:self]resetBorderWidth:1 borderColor:[Theme lineColor]] resetCornerRadius:2]labelResetTextAlignment:NSTextAlignmentCenter];
    
    CGFloat detailLW = __MAIN_WIDTH - self.titleL.left - (__MAIN_WIDTH - self.rightImageV.left);
    
    self.detailL = [[UILabel labelWithFrame:CGRectMake(self.titleL.left, CELL_HEIGHT - titleLH - titleLY, detailLW, self.titleL.height) font:FONT_DEFAULT_Light(13) text:@"" textColor:Label_Gray_Color] setupOnView:self];
    
    [[[UIView viewWithFrame:CGRectMake(0, CELL_HEIGHT - 0.5, __MAIN_WIDTH, 0.5)] setupOnView:self] resetBackgroundColor:[Theme lineColor]];
}
- (void)reloadDataModel:(CarModel *)model
{
    if ([model.carinfoModel.modelImg isNotNil]) {
        [self.iconImageV setImageWithURL:[NSURL URLWithString:model.carinfoModel.modelImg] placeholderImage:ImageNamed(@"BRCarStyleNormalImage")];
        self.iconImageV.height = self.iconImageV.width * self.iconImageV.image.size.height / self.iconImageV.image.size.width;
        self.iconImageV.top = (CELL_HEIGHT - self.iconImageV.height) / 2;
        
    }
    
    NSString * brandNumStr = model.carinfoModel.carno;
    CGSize titleLSize = [brandNumStr sizeWithFont:self.titleL.font maxWidth:self.detailL.width];
    self.titleL.text = [brandNumStr isNotNil] ? brandNumStr : @"车牌号待补充" ;
    self.titleL.textColor = [brandNumStr isNotNil] ? Label_Color : Label_Gray_Color;
    self.titleL.width = (titleLSize.width > 70 ? (titleLSize.width  + 10): self.titleL.width);
    self.grayTitleL.left = self.titleL.right;
    [self.grayTitleL setHidden:!model.carinfoModel.unDel];
    
    
    NSString * detailStr = [NSString stringWithFormat:@"%@ %@",model.carinfoModel.brandName, model.carinfoModel.modelName];
    self.detailL.text = ([model.carinfoModel.brandName isNotNil]|| [model.carinfoModel.modelName isNotNil]) ? detailStr : @"车型待补充";
    self.detailL.textColor = ([model.carinfoModel.brandName isNotNil]|| [model.carinfoModel.modelName isNotNil]) ? Label_Color : Label_Gray_Color;
    
}
+ (CGFloat)getCellHeight
{
    return CELL_HEIGHT;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
